#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
using namespace std;

#define SIZE (sizeof(struct stu))
#define PATH "tmp.txt"
#define N 2

typedef struct stu
{
  string name;
  int age;
}STU;

int main()
{
  STU stua[N], stub[N],*pa=stua, *pb=stub;

  printf("Write File:\n");
  for (int i=0; i<N; i++, pa++)
  {
    cin>>pa->name>>pa->age;
  }

  FILE *fp;
  if((fp = fopen(PATH, "wb+")) == NULL)
  {
      exit(1);
  }

  pa = stua;
  fwrite(pa, SIZE, 2, fp);
  
  printf("\nRead File:\n");
  
  rewind(fp);
  fread(pb, SIZE, 2, fp);

  for (int j=0; j<N; j++, pb++)
  {
    cout<<pb->name<<" "<<pb->age<<endl;
  }

  fclose(fp);
  return 0;
}
